Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
05-May-2025The
HttpCookieclass in ASP.NET (System.Web) is used to create, read, and manage cookies — small pieces of data stored on the client’s browser.Cookies are commonly used for storing user preferences, authentication tokens, session identifiers, or any small data that needs to persist between requests.
Namespace and Assembly
Difinition
This class represents an individual cookie — a name-value pair optionally with metadata like expiration date, path, domain, and security settings.
Constructors
Common Properties
NameValueExpiresDomainPathSecuretrue, the cookie is sent only over HTTPSHttpOnlytrue, JavaScript cannot access the cookieValuesCreating and Sending a Cookie to the Browser
Reading a Cookie
This reads the cookie from the user's browser on the next request.
Deleting a Cookie
You "delete" a cookie by setting its expiration date in the past:
Security Notes
HttpOnly = trueto prevent client-side JavaScript from accessing cookies.Secure = truefor HTTPS-only cookies.Session vs Persistent Cookie
Expiresset — deleted when the browser closesExpiresset — stored until expirationExample Scenario: Remember User's Language Preference